/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.com.remiseria.bo;

import ar.com.remiseria.dao.DomicilioDAO;
import ar.com.remiseria.entities.Domicilio;
import org.hibernate.HibernateException;

/**
 *
 * @author mcvalls
 */
public class DomicilioBO {
    
    DomicilioDAO domicilioDAO = new DomicilioDAO();
    
    public Domicilio saveNewDomicilio(Domicilio domicilio) throws Exception{
        
        try{
            domicilio = domicilioDAO.saveNew(domicilio);
        }catch(HibernateException hex){
            throw new Exception(hex);
        }
        
        return domicilio;
    }

    public Domicilio saveNewDomicilioIfNotExists(Domicilio destino) throws Exception{
        Domicilio domicilio = new Domicilio();
        try{
            domicilio = domicilioDAO.getDomicilioByTodosLosDatos(destino);
            if(domicilio != null){
                destino = domicilio;
            }else{
                destino = domicilioDAO.saveNew(destino);
            }
        }catch(HibernateException hex){
            throw new Exception(hex);
        }
        
        return destino;
    }
    
}
